
# 流量池相关视图
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect, get_object_or_404
from LogisticsCard.models import CardPool, PoolCardRelation
@login_required
def flowpool_list_view(request):
    """
    流量池列表视图，展示所有流量池信息。
    :param request: HttpRequest对象
    :return: 渲染流量池列表页面
    """
    pools = CardPool.objects.all().order_by('-created_at')
    return render(request, 'flowpool/index.html', {'pools': pools})
@login_required
def flowpool_create_view(request):
    """
    流量池创建视图，处理流量池表单提交。
    :param request: HttpRequest对象
    :return: 渲染流量池创建页面或跳转到列表
    """
    if request.method == 'POST':
        name = request.POST.get('name')
        remark = request.POST.get('remark', '')
        CardPool.objects.create(
            name=name,
            remark=remark
        )
        return redirect('flowpool_list')
    return render(request, 'flowpool/create.html')
from django.contrib.auth.models import User

@login_required
def user_flowpool_list_view(request):
    pools = CardPool.objects.filter(owner=request.user).order_by('-created_at')
    return render(request, 'flowpool/index.html', {'pools': pools})

@login_required
def flowpool_detail_view(request, pool_id):
    pool = get_object_or_404(CardPool, id=pool_id, owner=request.user)
    return render(request, 'flowpool/detail.html', {'pool': pool})
